<script lang="ts" setup>
import { reactive, toRefs, watch } from "vue"
import { ElTable } from "element-plus"
// 接口
import { getxjzhApi } from "@/api/subordinate/index"
// import { Search, Refresh } from "@element-plus/icons-vue"
import { usePagination } from "@/hooks/usePagination"
const { paginationData, handleCurrentChange, handleSizeChange } = usePagination()
// 缓存
defineOptions({
  name: "subordinateList"
})

const data = reactive<any>({
  formData: {},
  searchData: {},
  tableData: ""
})
const { tableData } = toRefs(data)
//  #region 搜索
// const searchFormRef = ref<FormInstance | null>(null)
// const handleSearch = () => {
//   if (paginationData.currentPage === 1) {
//     getTableData()
//   }
//   paginationData.currentPage = 1
// }
// const resetSearch = () => {
//   searchFormRef.value?.resetFields()
//   if (paginationData.currentPage === 1) {
//     getTableData()
//   }
//   paginationData.currentPage = 1
// }
// #endregion

// 查下级
const getTableData = () => {
  getxjzhApi({
    page: paginationData.currentPage,
    size: paginationData.pageSize
  }).then((res: any) => {
    paginationData.total = res.data.total
    tableData.value = res.data.list
    console.log(res, "查询的数据")
  })
}
getTableData()

/** 监听分页参数的变化 */
watch([() => paginationData.currentPage, () => paginationData.pageSize], getTableData, { immediate: true })
</script>

<template>
  <div class="app-container">
    <!-- <el-card shadow="never" class="search-wrapper">
      <el-form ref="searchFormRef" :inline="true" :model="searchData">
        <el-form-item prop="xxx" label="下级账号">
          <el-select v-model="searchData.xxx" clearable placeholder="请选择下级账号" style="width: 240px">
            <el-option v-for="item in xxx" :key="item.user_id" :label="item.user_name" :value="item.user_id" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :icon="Search" @click="handleSearch">查询</el-button>
          <el-button :icon="Refresh" @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card> -->
    <!-- 中间部分 -->
    <el-card shadow="never">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="user_name" label="用户名" align="center" />
        <el-table-column prop="user_mobile" label="用户手机号" align="center" />
        <el-table-column prop="user_invite" label="用户邀请码" align="center" />
        <el-table-column prop="user_sex" label="用户性别" align="center" />
        <el-table-column prop="user_card_id" label="用户身份证号" align="center" />
        <el-table-column prop="user_card_name" label="用户身份证姓名" align="center" />
        <!-- <el-table-column label="详情" align="center">
          <template #default="scope">
            <el-button type="primary" size="small" @click="handleClick(scope.row)">查看详情</el-button>
            <el-button
              style="display: none"
              type="primary"
              size="small"
              @click="handleXZ(scope.row)"
              :disabled="scope.row.withdrawals_state.state === '未提现'"
              >下载</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>
      <div class="pager-wrapper">
        <el-pagination
          background
          :layout="paginationData.layout"
          :page-sizes="paginationData.pageSizes"
          :total="paginationData.total"
          :page-size="paginationData.pageSize"
          :currentPage="paginationData.currentPage"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>

<style lang="scss" scoped>
.search-wrapper {
  margin-bottom: 20px;
  :deep(.el-card__body) {
    padding-bottom: 2px;
  }
}
.pager-wrapper {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>
